import tool from '@/utils/tool'

// 请求状态错误
export const httpLogError = (error, msg) => {
  error.message = msg
  uni.showToast({
    title: msg,
    icon: 'error',
    duration: 2000
  })
}

// api请求错误
export const requestError = (response) => {
  return new Promise((resolve, reject) => {
    const { data } = response
    const msg = `api请求出错 ${response.config.url}：${data.message}`
    uni.showToast({
      title: msg,
      icon: 'error',
      duration: 2000
    })
    reject(data)
  })
}


// 保持重新登录Modal的唯一性
export const throttleToLogin = (loginBack) => {
  loginBack.value = true
  uni.showModal({
    title: '提示：',
    content: '登录已失效， 请重新登录',
    confirmText: '重新登录',
    onOk: () => {
      loginBack.value = false
      tool.data.remove('TOKEN')
      tool.data.remove('USER_INFO')
      tool.data.remove('MENU')
      tool.data.remove('PERMISSIONS')
      uni.reLaunch()
    }
  })
}

// // 登录失效
// export const throttleToLogin = () => {
//   // uni.navigateTo({ url: '/pages/login/login' })
// }
